import hashlib, os, sys, typing
selfDir = os.path.dirname(__file__)
sys.path.append(selfDir)
protoFile = os.path.join(selfDir, 'elegant.proto')
with open(protoFile, 'rb') as f:
    md5 = hashlib.md5(f.read()).hexdigest()
try:
    with open(f'{protoFile}.md5', 'r', encoding = 'utf-8') as f2:
        md52: typing.Optional[str] = f2.read()
except FileNotFoundError:
    md52 = None
if md5 != md52:
    os.unlink(os.path.join(selfDir, 'elegant_pb2.py'))
    os.unlink(os.path.join(selfDir, 'elegant_pb2_grpc.py'))
    with open(f'{protoFile}.md5', 'w', encoding = 'utf-8') as f2:
        f2.write(md5)
try:
    from elegant_pb2 import *
    from elegant_pb2_grpc import *
except ModuleNotFoundError:
    os.system('python -m grpc_tools.protoc -I"%s" --python_out="%s" --grpc_python_out="%s" "%s"' % (selfDir, selfDir, selfDir, protoFile))
    from elegant_pb2 import *
    from elegant_pb2_grpc import *
